//
//  NWViewController+HBDNavigationBar.m
//  NongWanCloud
//
//  Created by YueWen on 2018/5/8.
//  Copyright © 2018年 YueWen. All rights reserved.
//

#import "UIViewController+HBDNavigationBar.h"
#import "COHBDNavigationBar.h"
#import "RITLKit.h"
#import "HBDNavigationBar.h"
#import "UIViewController+HBD.h"

@implementation UIViewController (HBDNavigationBar)

- (void)setDefaultNavigationBarWhenHasParentNavigationController
{
    self.hbd_barStyle = self.nav_barStyle;
    self.hbd_barTintColor = self.nav_barTintColor;
    self.hbd_tintColor = self.nav_tintColor;
    self.hbd_barAlpha = self.nav_barAlpha;
    self.hbd_barHidden = self.nav_barHidden;
    self.hbd_barShadowHidden = self.nav_barShadowHidden;
    self.hbd_backInteractive = self.nav_backInteractive;
    
    if (self.nav_barImage) {
        self.hbd_barImage = self.nav_barImage;
    }
    
    if (!self.nav_titleTextAttributes) {
        self.hbd_titleTextAttributes = @{NSFontAttributeName:self.nav_titleFont,
                                         NSForegroundColorAttributeName:self.nav_titleColor};
    }else {
        self.hbd_titleTextAttributes = self.nav_titleTextAttributes;
    }
    
    UINavigationBar *bar = self.navigationController.navigationBar;
    if ([bar isKindOfClass:COHBDNavigationBar.class]) {
        COHBDNavigationBar *hbdBar = ((COHBDNavigationBar *)bar);
        hbdBar.shadowImage = self.nav_shadowImage;
        hbdBar.shadowImageViewOffsetY = 0;
        hbdBar.shadowImageViewHeight = 5;
    }
    
    [self setNavigationBarShadowViewHidden:self.nav_mutableBarShadowHidden];
    [self hbd_setNeedsUpdateNavigationBar];
    [self hbd_setNeedsUpdateNavigationBarAlpha];
    [self hbd_setNeedsUpdateNavigationBarColorOrImage];
    [self hbd_setNeedsUpdateNavigationBarShadowAlpha];
}


- (UIBarStyle)nav_barStyle{
    return UIBarStyleDefault;
}

- (UIColor *)nav_barTintColor{
    return UIColor.whiteColor;
}

- (UIImage *)nav_barImage{
    return nil;
}

- (UIColor *)nav_tintColor{
    return RITLSimpleColorFromIntRBG(34);
}

- (float)nav_barAlpha{
    return 1.0;
}

- (BOOL)nav_barHidden{
    return false;
}

- (BOOL)nav_barShadowHidden{
    return false;
}

- (BOOL)nav_mutableBarShadowHidden {
    return false;
}

- (BOOL)nav_backInteractive{
    return true;
}

- (UIColor *)nav_titleColor
{
    return QDSColorDefaultBlack;
}

- (UIFont *)nav_titleFont{
    return RITLMediumFont(18);
}


- (NSDictionary *)nav_titleTextAttributes{
    return nil;
}

    
- (UIImage *)nav_shadowImage {
    return @"nav_shadow_bottom".ritl_image;
}


- (void)setNavigationBarShadowViewHidden:(BOOL)isHidden {
    UINavigationBar *bar = self.navigationController.navigationBar;
    if ([bar isKindOfClass:HBDNavigationBar.class]) {
        HBDNavigationBar *hbdBar = ((HBDNavigationBar *)bar);
        hbdBar.shadowImageView.hidden = isHidden;
    }
}

@end
